package com.jingdong.interview;

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author ZhangyiA
 * @describe: 最小生成树 ( 有点并查集的意味 )
 * @date 2021/07/09
 */

class Point{
    int u , v , c;
    public Point(int u , int v , int c){
        this.u = u ;  this.v = v ;  this.c = c;
    }

}

public class Three_BuildCircuit {

    public int ans = 0 , cnt = 0;

    public int find(int[] parent , int i){
        return parent[i] == -1 ? i : find(parent , parent[i]);
    }

    public void union(int[] parent , int x , int y , int c){
        int x_parent = find(parent , x);
        int y_parent = find(parent , y);
        if(x_parent != y_parent){
            parent[x_parent] = y_parent;
            ans += c;
            cnt ++;
        }
    }

    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        Three_BuildCircuit circuit = new Three_BuildCircuit();
        int n = input.nextInt();
        int m = input.nextInt();
        Point[] node = new Point[n + 1];
        for(int i = 1 ; i <= m ; i ++){
            int u = input.nextInt();
            int v = input.nextInt();
            int c = input.nextInt();
            node[i] = new Point(u, v, c);
        }
        Arrays.sort(node ,1, n + 1 , (n1 , n2) -> n2.c - n1.c); // 从 1 - n 区间进行排序

        int[] parent = new int[n + 1];
        Arrays.fill(parent , -1);
        for(int i = 1 ; i <= m ; i ++){
            if(circuit.cnt >= n - 1){
                break;
            }
            circuit.union(parent , node[i].u , node[i].v , node[i].c);
        }
        if(circuit.cnt < n - 1){
            System.out.println("No solution");
        } else{
            System.out.println(circuit.ans);
        }
    }

}
